package com.crm.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.URLEncoder;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class xiaoyou {
 public static void main(String[] args) {
	 
	 try{
 
		 
 			String cp ="测试";
			String sss = URLEncoder.encode(cp+" 电话|手机|联系方式");
		    Document doc = Jsoup.connect("http://192.168.1.126/xiaoyou/qq?key=123456").data("msg","系统消息：测试恭喜某某以3万5千元签下某某公司").data("gpn","测试").userAgent("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; BIDUBrowser 2.x)").post();
			
			// Document doc = Jsoup.connect("http://192.168.1.126/xiaoyou/qqtip?key=123456").data("msg","测试群发消息").data("qqnick","开发设计").userAgent("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; BIDUBrowser 2.x)").post();
			
			
			/* Elements  els = doc.select(".result");
			 for(Element e:els){
				String title =  e.select("h3").text();
				String content =  e.select(".c-abstract").text();
			 
				  if(isphone(content) && isName(cp,content)){
					System.out.println(content);
				  } 
			 }*/
			 
		}catch(Exception e){
			e.printStackTrace();
		}
	 
	 
	 
}
 
 public static Element  url(String cp){
	 try{
			Document doc = Jsoup.connect("http://jzsc.mohurd.gov.cn/dataservice/query/comp/list").timeout(62000).data("complexname",cp).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").post();
			Element  el = doc.select(".cursorDefault  tr").get(0);
			return el;
	 }catch(Exception e){
		return url(cp);
	 }
	 
	 
 } 
 public static String  url2(String href ,String cp){
	 try{
		 Document doc1 = Jsoup.connect("http://jzsc.mohurd.gov.cn"+href).data("complexname",cp).timeout(62000).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").get();
			String address = doc1.select(".datas_table tbody tr").get(3).select("td").get(0).text();
			return address;
	 }catch(Exception e){
		return url2(href,cp);
	 } 
 } 
 
 public static Elements  url3(String href ,String cp){
	 try{
		 Document doc2 = Jsoup.connect("http://jzsc.mohurd.gov.cn"+href.replace("compDetail", "caDetailList")).timeout(62000).data("complexname",cp).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").get();
			 
		  Elements  trs = doc2.select(".cursorDefault tr");
		    trs.get(0);
			return trs;
	 }catch(Exception e){
		return url3(href,cp);
	 } 
 } 
 
 
 
 public static void readTxtFileTwo(String filePath){
     try {
             String encoding="GBK";
             File file=new File(filePath);
             if(file.isFile() && file.exists()){ //判断文件是否存在
                 InputStreamReader read = new InputStreamReader(
                 new FileInputStream(file),encoding);//考虑到编码格式
                 BufferedReader bufferedReader = new BufferedReader(read);
                 String lineTxt = null;
                 int i =0;
                 StringBuffer  table = new StringBuffer("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head><body><table border=1><tr><td>公司名称</td><td>资质</td><td>地址</td></tr>");
                 while((lineTxt = bufferedReader.readLine()) != null){
                     System.out.println(i+"---"+lineTxt);
                	 try{
                		 
     
                	//		Document doc = Jsoup.connect("http://59.175.169.110/Ewmwz/QyManage/QyzzSearch.aspx?ssl=107&__EVENTTARGET=lbtnGo&__EVENTARGUMENT=").data("hSsl","107").data("txtPageIndex","7").data("__EVENTVALIDATION","/wEWCwK/1PzdCQK4s/fhCgLyxsSSBAKln/PuCgKSq+DOBgLtgtDiCgLk9PbGCgLvwfqHDwKT7byBDAKl+aafDQLznLb/CI2nZuTv9CMX1LBUrH6Ogn9RvLjYxdRzF34fVTwKXySa").data("__VIEWSTATE","/wEPDw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0; Windows NT 6.1; WOW64; Trident/6.0; BIDUBrowser 2.x)").post();
                			String cp =lineTxt;
                			//String sss = URLEncoder.encode(cp+" 电话|手机|联系方式");
                			//Document doc = Jsoup.connect("http://jzsc.mohurd.gov.cn/dataservice/query/comp/list").timeout(62000).data("complexname",cp).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").post();
                			Element  el = url(cp);//doc.select(".cursorDefault  tr").get(0);
                			Elements td = el.select(".primary");
                			if(td!=null&&StringUtils.isNotEmpty(td.text())){
                				 if(td.text().equals(cp)){
                					//  table.append("<tr><td>"+cp+"</td><td>"+contents+"</td</tr>");
                					String href =  td.select("a").attr("href");
                					// Document doc1 = Jsoup.connect("http://jzsc.mohurd.gov.cn"+href).data("complexname",cp).timeout(62000).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").get();
                					String address =url2(href,cp); //doc1.select(".datas_table tbody tr").get(3).select("td").get(0).text();
                					 //System.out.println(address);
                					 
                					// Document doc2 = Jsoup.connect("http://jzsc.mohurd.gov.cn"+href.replace("compDetail", "caDetailList")).timeout(62000).data("complexname",cp).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").get();
                 					 
                					  Elements  trs = url3(href,cp);// doc2.select(".cursorDefault tr");
                					  String zzmc = "";
                					  String zzrq ="";
                					   if(trs.size()>1){
                						  int y =0;
                						  for(Element tr:trs){
                							  Elements tds =  tr.select("td");
                							  if(tds.size()>2){
                								
                								  
                								 /* for(Element tdobj:tds){
                									 String  zzmchead = tdobj.attr("data-header");
                									 if(zzmchead.equals("资质名称")){
                										 
                									 }
                								  }*/
                								   zzrq = tds.get(4).text();//日期
                								   zzmc +="["+zzrq+"]" +tds.get(3).text()+"<br>";//名称
                								  
                							  }else{
                								    zzmc += tds.get(1).text()+"<br>";
                							  }
                							 // y++;
                						  }
                					 }else{
                						  Elements tds =  trs.get(0).select("td");
                						   zzrq = tds.get(4).text();//日期
                						   zzmc += "["+zzrq+"]" +tds.get(3).text();//名称
        								 
                					  } 
                					 
                					  table.append("<tr><td>"+cp+"</td><td>"+zzmc+"</td><td>"+address+"</td></tr>");
                					  //<tr><td>公司名称</td><td>资质</td><td>发证日期</td><td>地址</td></tr>
                					  
                    				 //System.out.println("----"+);
                				 }
                				
                				
                			}
                			
                			  try {
     		                     //sleep()方法导致了程序暂停执行指定的时间，让出cpu该其他线程，
     		                 //但是他的监控状态依然保持者，当指定的时间到了又会自动恢复运行状态。
     		                     //在调用sleep()方法的过程中，线程不会释放对象锁。
			     		                   Thread.sleep(5000);
			     		       } catch (Exception e) {
			     	                    e.printStackTrace();
			     		  }
                			
                			/* if(contents.length()>0){
                				  table.append("<tr><td>"+cp+"</td><td>"+contents+"</td</tr>");
                				 
                			 }*/
                			//System.out.println();
                			
                		}catch(Exception e){
                			e.printStackTrace();
                		}
                	  if(i>500){
                	   // break;
                		  try{
                			  i=0;
                      		Date d =  new Date();
                      		
                      		   table.append("</table></body></html>");
                      		  PrintStream printStream = new PrintStream(new FileOutputStream("d://report"+d.getTime()+".html")); 
                                printStream.println(table.toString()); 
                                System.out.println("已成功输出");
                      		  table = new StringBuffer("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head><body><table border=1><tr><td>公司名称</td><td>资质</td><td>地址</td></tr>");
                      		 
                		  }catch(Exception ec){
                			  ec.printStackTrace();
                		  }
                		
                		 
                	 }  
                	 i++;
                 }
                 table.append("</table></body></html>");
                 read.close();
                 
              try{
            	  Date d =  new Date();
                 PrintStream printStream = new PrintStream(new FileOutputStream("d://report"+d.getTime()+".html")); 
                 printStream.println(table.toString()); 
                 System.out.println("已成功输出");
            	 
       		  }catch(Exception ec){
       			  ec.printStackTrace();
       		  }
     }else{
         System.out.println("找不到指定的文件");
     }
     } catch (Exception e) {
         System.out.println("读取文件内容出错");
         e.printStackTrace();
     }
     
  
 }
 
 
 public static void readTxtFile(String filePath){
     try {
             String encoding="GBK";
             File file=new File(filePath);
             if(file.isFile() && file.exists()){ //判断文件是否存在
                 InputStreamReader read = new InputStreamReader(
                 new FileInputStream(file),encoding);//考虑到编码格式
                 BufferedReader bufferedReader = new BufferedReader(read);
                 String lineTxt = null;
                 int i =0;
                 StringBuffer  table = new StringBuffer("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head><body><table border=1><tr><td>公司名称</td><td>检索内容</td</tr>");
                 while((lineTxt = bufferedReader.readLine()) != null){
                     System.out.println(lineTxt);
                	 try{
                		 
     
                	//		Document doc = Jsoup.connect("http://59.175.169.110/Ewmwz/QyManage/QyzzSearch.aspx?ssl=107&__EVENTTARGET=lbtnGo&__EVENTARGUMENT=").data("hSsl","107").data("txtPageIndex","7").data("__EVENTVALIDATION","/wEWCwK/1PzdCQK4s/fhCgLyxsSSBAKln/PuCgKSq+DOBgLtgtDiCgLk9PbGCgLvwfqHDwKT7byBDAKl+aafDQLznLb/CI2nZuTv9CMX1LBUrH6Ogn9RvLjYxdRzF34fVTwKXySa").data("__VIEWSTATE","/wEPDwULLTE0MDIxNzQ2NTIPZBYCAgMPZBYQAgMPFgIeCWlubmVyaHRtbAUh5bu6562R5Lia5LyB5Lia6LWE6LSo5L+h5oGv5p+l6K+iZAILDxYCHwAFaeazqO+8muacrOafpeivouS7hemZkOWcqOaWsOeJiOihjOaUv+WuoeaJueezu+e7n+WKnueQhui/h+W7uuetkeS4muS8geS4mui1hOi0qOihjOaUv+iuuOWPr+S6i+mhueeahOS8geS4mmQCDQ8WAh4LXyFJdGVtQ291bnQCFBYoZg9kFgJmDxUKATEGMTg3MzQzBTY1MTU0AzEwNyTmuZbljJfkuK3ng4Hlu7rorr7lt6XnqIvmnInpmZDlhazlj7gSOTE0MjExMjU1NzM3MjE0MDMyCemCteWwj+agixXl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DIwOTg2NjkKMjAxNi0wOC0wOGQCEg9kFgJmDxUKAjE5BjE5MDQ2MgU2OTAwMQMxMDck5rmW5YyX6ZSm5Y6m5bu66K6+5pyJ6ZmQ6LSj5Lu75YWs5Y+4EjkxNDIwNjAwNzQxNzczNTEwWQnog6HmtKrlkK8V5bu6562R5Lia5LyB5Lia6LWE6LSoCkQxNDIwOTg4NjEKMjAxNi0wOC0yOWQCEw9kFgJmDxUKAjIwBjE5MDk4NgU2MjIwOQMxMDck5rmW5YyX5ZCM55Ge5bu66K6+5Y+R5bGV5pyJ6ZmQ5YWs5Y+4EjkxNDIwMTA2MDkyMDA2ODQ3NAnnjovlhajli4cV5bu6562R5Lia5LyB5Lia6LWE6LSoCkQxNDIwOTkwNDkKMjAxNi0wOC0yOWQCDw8PFgIeBFRleHQFATRkZAIRDw8WAh8CBQM4ODhkZAITDw8WAh8CBQUxNzc0NGRkAhcPDxYCHgdFbmFibGVkZ2RkAhkPDxYCHwNnZGRk8E53rp2C/lW2FRxmxylNzeV/Y/HiNYZ2hIDEZsfSp58=").timeout(62000).header("Origin", "http://59.175.169.110").header("Referer", "http://59.175.169.110/Ewmwz/QyManage/QyzzSearch.aspx?ssl=107").userAgent("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; BIDUBrowser 2.x)").post();
                			String cp =lineTxt;
                			String sss = URLEncoder.encode(cp+" 电话|手机|联系方式");
                			Document doc = Jsoup.connect("https://www.baidu.com/s?wd="+sss+"&rsv_spt=1&rsv_iqid=0x9b82a590000057ef&issp=1&f=8&rsv_bp=1&rsv_idx=2&ie=utf-8&rqlang=cn&tn=baiduhome_pg&rsv_enter=0&inputT=849&rsv_t=6682eK25zVrc6zOj%2FYjrgI6AgKETHWJu8wOTSEbuq%2Fc0oXfI30Vx%2BubfRnA3lh18c4kW&oq=%25E6%25B9%2596%25E5%258C%2597%25E9%2594%25A6%25E5%258E%25A6%25E5%25BB%25BA%25E8%25AE%25BE%25E6%259C%2589%25E9%2599%2590%25E8%25B4%25A3%25E4%25BB%25BB%25E5%2585%25AC%25E5%258F%25B8%2520%25E7%2594%25B5%25E8%25AF%259D%257C%25E6%2589%258B%25E6%259C%25BA%257C%25E8%2581%2594%25E7%25B3%25BB%25E6%2596%25B9%25E5%25BC%258F&rsv_pq=93112c3d00007901&rsv_sug3=46&rsv_n=2&rsv_sug2=0&rsv_sug4=849").userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").get();
                			 Elements  els = doc.select(".result");
                			 String contents ="";
                			 for(Element e:els){
                				String title =  e.select("h3").text();
                				String content =  e.select(".c-abstract").text();
                				//System.out.println(title+"----"+isphone(content)+"--"+isName(cp,content));
                			 
                				  if(isphone(content) && isName(cp,content)){
                					  contents += content+"</br>";
                					//System.out.println(content);
                				  } 
                			 }
                			 if(contents.length()>0){
                				  table.append("<tr><td>"+cp+"</td><td>"+contents+"</td</tr>");
                				 
                			 }
                			//System.out.println();
                			
                		}catch(Exception e){
                			e.printStackTrace();
                		}
                	 /*if(i>10){
                		 break;
                	 }*/
                	 i++;
                 }
                 table.append("</table></body></html>");
                 read.close();
                 
                 
                  
                 PrintStream printStream = new PrintStream(new FileOutputStream("d://report.html")); 
                 printStream.println(table.toString()); 
                 System.out.println("已成功输出");
     }else{
         System.out.println("找不到指定的文件");
     }
     } catch (Exception e) {
         System.out.println("读取文件内容出错");
         e.printStackTrace();
     }
     
  
 }
 
 public static boolean isphone(String str)  {  
     String regExp = "^((?!(\\d{7})).)*$";  // "^((?!(1[3|4|5|8|7][0-9]\\d{8})).)*$"
     Pattern p = Pattern.compile(regExp);  
     Matcher m = p.matcher(str);  
     return !m.matches();  
 }  
 
 public static boolean isName(String ti,String str)  {  
     String regExp = "^((?!"+ti+").)*$";  // "?1[3|4|5|8][0-9]\\d{8}*+$";  
     Pattern p = Pattern.compile(regExp);  
     Matcher m = p.matcher(str);  
     return !m.matches();  
 }  
 
 
 
 
 
 
 
 
}
